/**
 * Created by Administrator on 2015/11/24.
 */

var a = 1 ;
console.log(typeof a);//number

var b = '1';
console.log(typeof b);//string

var c = {};
console.log(c.d === undefined);//true

if(a){//output == undefined
    console.log('undefined');
}

if(null){//no output
    console.log('undefined');
}

if(undefined){//no output
    console.log('undefined');
}

var aa = {};
aa.aa = {};
aa.aa.aa = {
    dd:1
};
console.log((aa['aa'])['aa']);

var date = new Date();
console.log(Date.now());
console.log(typeof date);

var d = [1,2];
console.log(d.length);
d.push(3);
console.log(d.length);

var obj ={}
console.log(typeof obj);

var page = 1;
console.log('dd '+(page+1)+' dd');

console.log(5/7 + 1);

var done = done||{};
console.log(done);

var f= {};
if(f){
    console.log('test a');
}
for(var i in f){//没有输出
    console.log(f[i])
}

console.log(undefined||{})

var s = 'property';
console.log(s==='property')

var myarr = [1,2,3,4];
console.log(myarr.join(''))

var myarrstr = ['abc','efg','hig'];
console.log(myarrstr.join(''));

console.log(undefined||'');
console.log('dongge'||'');

console.log(undefined || false)

console.log(typeof 'str');

console.log({1:2});

var obj1 = {name:'zeus'}
try{
    console.log(obj1.address.name)
}catch (err){
    console.log(err);
}

function f1(){xyz;}
console.log(f1.toString())
console.log(/xyz/.test(function(){xyz;}));

console.log(f1.toString === Object.prototype.toString)
console.log(f1.toString === Function.prototype.toString)
function f2(){ xyz;}
console.log(f1 instanceof Function);
console.log(f2 instanceof Function);
console.log(typeof f1);

+function(){
    console.log([1,2,3]);
    var str = [1,2].reduce(function(p,c,i,a){
        if(i===0)
            return c;
        else
            return p+','+c;
    },'');
    console.log(str)
    //array.join
}();
+function(){
    console.log('login-register');
    var allowedUrls = ['/login','/register'];
    var url = '/login';
    for(var i = 0;i<allowedUrls.length;i++){
        var r = new RegExp("^"+allowedUrls[i]+"$");
        console.log(r.test(url));
    }
    console.log('login-register-end');
}();

+function () {

    var state = 0;
    if(state){
        console.log(state);
    }else{
        console.log(state||'d')
    }
}();

+function(){
    function a(){};
    console.log(typeof a == 'function');
}();

+function(){
    //if(page1){ //error page1 is not defined
    //    console.log('test undefined variable')
    //}
    function testUndefined(page1){
        console.log(page1);
        if(!page1){
            console.log('test page1');
        }
    }
    testUndefined();
    //总结
    /**
     * 对于程序中未声明（直接var或者采用赋值来声明变量），如果直接使用会报错。
     * 对于函数中的参数，如果调用时没有给某些参数赋值，那么这些参数默认会初始化
     * 为undefined
     *
     */
}();

+function(){
    var a=[{name:'dongge'},{name:'dongge'}];
    a.forEach(function(b){
        b.age = 1;
    })
    console.log(a);
}();

